<template>
  <el-dialog :title="title" :visible.sync="open" width="400px" append-to-body :close-on-click-modal="false" @close="closeModal">
    <el-form ref="form" :model="form" :show-message="false" label-width="120px">
      <el-form-item label="药材最大用量" prop="doseMax" required>
        <div class="disFlx">
          <el-input-number
            :controls="false"
            :precision="0"
            :min="0"
            v-model="form.doseMax"
            placeholder="请输入药材最大用量"
          />
        </div>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="open = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { batchSetDoseMax } from '@/api/saas/tcm.js'
export default {
  data() {
    return {
      title: "批量设置最大用量",
      open: false,
      form: {
        ids: undefined,
        doseMax: undefined
      },
    };
  },
  methods: {
    openModal(ids) {
      this.open = true;
      this.form.ids = ids || undefined;
    },
    closeModal() {
      this.$refs["form"].resetFields();
      Object.assign(this.$data, this.$options.data()); // 存在自定义校验规则不能重置data
    },
    submitForm() {
      const that = this;
      that.$refs["form"].validate(async (valid) => {
        if (valid) {
          batchSetDoseMax(that.form).then(()=>{
            that.$message.success("设置成功");
            that.$emit("refresh");
            that.closeModal();
          })
        }
      })
    }
  },
};
</script>

<style lang="scss" scoped></style>
